<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 1. 交换两个变量的值

        // 1.1 使用第三方变量
        var num1 = 100;
        var num2 = 888;
        var temp;

        temp = num1;
        num1 = num2;
        num2 = temp;
        // console.log(num1, num2);

        // 1.2 计算的方式
        var n1 = 100;
        var n2 = 888;
        n1 = n1 + n2;  // n1 = 988
        n2 = n1 - n2;  // n2 = 100
        n1 = n1 - n2;  // n1 = 888
        // console.log(n1, n2);

        // 1.3 解构的交换
        let count1 = 100;
        let count2 = 888;
        // 利用了数组的解构来实现交换
        ;[count2, count1] = [count1, count2];
        console.log(count1, count2);
    </script>
</body>

</html>